﻿namespace OrderControl
{
    public class Commodity
    {
        private string name;
        private double unitPrice;

        public string Name
        {
            get => name;
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    name = value;
                }
                else
                {
                    throw new OrderPropertyException("Commodity name cannot be empty.");
                }
            }
        }

        public double UnitPrice
        {
            get => unitPrice;
            set
            {
                if (value > 0)
                {
                    unitPrice = value;
                }
                else
                {
                    throw new OrderPropertyException("Commodity unit price cannot be less than or equal to zero.");
                }
            }
        }

        public Commodity(string name, double unitPrice)
        {
            this.Name = name;
            this.unitPrice = unitPrice;
        }
        public Commodity() { }

        public override string ToString()
        {
            return "[Commodity] Name: " + name
                + ", Unit-Price: " + unitPrice;
        }

        public override bool Equals(object obj)
        {
            return obj is Commodity commodity &&
                   name == commodity.name &&
                   unitPrice == commodity.unitPrice;
        }
    }
}
